# -*- coding:utf-8 -*-
class HtmlOutputer(object):
    def __init__(self):
        self.datas = []

    def output(self, data):
        self.collect_data(data)
        self.output_html()

    def collect_data(self, data):
        if data is None:
            return
        if type(data) == list:
            self.datas += data
        else:
            self.datas.append(data)

    def output_html(self):
        fout = open('dist/大伟吉他教室.html', 'w', encoding='utf-8')

        fout.write('<html>')
        fout.write('<head>')
        fout.write('<meta charset="UTF-8">')
        fout.write('</head>')
        fout.write('<body>')
        fout.write('<table>')

        for data in self.datas:
            fout.write('<tr>')
            fout.write('<td width=100px>%s</td>' % data['title'])
            fout.write('<td width=100px>%s</td>' % data['url'])
            fout.write('</tr>')

        fout.write('</table>')
        fout.write('</body>')
        fout.write('</html>')
